﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using webDemo.Models;

namespace webDemo.Controllers
{
    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> _logger;

        private readonly MyInfoOptions options1;
        private readonly MyInfoOptions options2;
        private readonly MyInfoOptions options3;

        public HomeController(ILogger<HomeController> logger, IOptions<MyInfoOptions> options
          , IOptionsSnapshot<MyInfoOptions> optionsSnapshot
          , IOptionsMonitor<MyInfoOptions> optionsMonitor)
        {
            options1 = options.Value;
            options2 = optionsSnapshot.Value;
            options3 = optionsMonitor.CurrentValue;
     
            _logger = logger;
        }

        public IActionResult Index()
        {
            return Json(new MyInfoOptions[] { options1, options2, options3 });
        }

        public IActionResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
